public class Test {



    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m-1;
        int j = n-1;
        int k = m+n-1;
        while(i>=0 && j>=0) {
            if(nums2[j] > nums1[i]) {
                nums1[k] = nums2[j];
                j--;
                k--;
            }else {
                nums1[k] = nums1[i];
                k--;
                i--;
            }

        }
        while(j>=0) {
            nums1[k] = nums2[j];
            k--;
            j--;
        }

    }
    public static void main(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int[] nums2 = {2,5,6};
        merge(nums1,3,nums2,3);
        for (int i = 0; i < 6; i++) {
            System.out.print(nums1[i]+" ");
        }
    }
    public static int removeDuplicates(int[] nums) {
        int[] flag = new int[201];
        int k = nums.length;//记录数组长度
        for (int i = nums.length-1; i >=0; i--) {
            int tmp = flag[nums[i]+100];
            if(tmp >=1) {
                for (int j = i; j < k-1; j++) {
                    nums[j] = nums[j+1];
                }
                k--;
            }else {
                flag[nums[i]+100]++;
            }
        }
        return k;

    }
    public static void main2(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        int len = removeDuplicates(nums);
        System.out.println(len);
        for (int i = 0; i < len; i++) {
            System.out.print(nums[i]+" ");
        }
    }
    public static int removeElement(int[] nums, int val) {
        int len = nums.length-1;//记录数组最大下标

        for (int i = nums.length-1; i >=0; i--) {
           if(nums[i] == val) {
               if(i == len) {
                   len--;
               }else {
                   for(int j = i;j<len;j++) {
                       nums[j] = nums[j+1];
                   }
                   len--;
               }
           }
        }
        return len+1;
    }

    public static void main1(String[] args) {
        int[] nums = {1,2,3,4,5,6,1,1};
        int len = removeElement(nums,1);
        System.out.println(len);
        for (int i = 0; i < len; i++) {
            System.out.print(nums[i]+" ");
        }
    }
}
